let app = getApp();
Page({
  data: {
    canIUse: wx.canIUse("button.open-type.getUserInfo"),
    currentTab: 0,
    topOne: true,
    topTwo: true,
    topThree: false,
    items: [
      {
        iconPath: "/pages/img/index2.png",
        selectedIconPath: "/pages/img/index1.png",
        text: "首页",
        title: "拿来换",
      },
      {
        iconPath: "/pages/img/car2.png",
        selectedIconPath: "/pages/img/car1.png",
        text: "商城",
        title: "商城",
      },
      {
        iconPath: "/pages/img/qr.png",
        selectedIconPath: "/pages/img/qr.png",
        text: "扫描",
        title: "扫描",
      },
      {
        iconPath: "/pages/img/car2.png",
        selectedIconPath: "/pages/img/car1.png",
        text: "购物车",
        title: "购物车",
      },
      {
        iconPath: "/pages/img/my2.png",
        selectedIconPath: "/pages/img/my1.png",
        text: "个人",
        title: "个人",
      },
    ],
  },
  getUserInfo: function (e) {
    if (e.detail.userInfo) {
      app.userInfo = e.detail.userInfo;
      // wx.reLaunch({
      //   url: '/pages/index/index',
      // })
      this.setData({
        topTwo: false,
        topThree: true,
      });
    } else {
      wx.showModal({
        title: "警告",
        content: "您点击了拒绝授权，将无法进入小程序，请选择授权",
        showCancel: false,
        confirmText: "返回授权",
      });
    }
  },
  swichNav: function (e) {
    let that = this;
    if (this.data.currentTab !== e.target.dataset.current) {
      that.setData({
        currentTab: e.target.dataset.current,
      });
      wx.setNavigationBarTitle({
        title: that.data.items[e.target.dataset.current].title,
      });
    }
  },
  onLoad: function (option) {
    wx.hideHomeButton({
      complete: (res) => {},
    });
    // 获取用户信息
    wx.getSetting({
      success: (res) => {
        //已经授权的话
        if (res.authSetting["scope.userInfo"]) {
          console.log(1);
          this.setData({
            topOne: false,
            topTwo: false,
            topThree: true,
          });
        } else {
          this.setData({
            topOne: false,
            topTwo: true,
          });
        }
      },
    });
    // 引入SDK核心类
    var QQMapWX = require("../../utils/qqmap-wx-jssdk.js");
    var qqmap;
    // 实例化API核心类
    var qqmapsdk = new QQMapWX({
      key: "XZBBZ-BMVC3-4GI3J-YX44K-WFLXT-EMBIC", // 必填
    });
  },
});
